/**
 * 
 */
package co.fitstart.entity.order;

import java.beans.Transient;
import java.math.BigDecimal;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonIdentityReference;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;

/**
 * @author downpour
 *
 */
@Entity
@Table(name = "order_attr")
@JsonIgnoreProperties(value={"hibernate_lazy_initializer","handler","fieldHandler"})
public class OrderAttribute {
    
    @Id
    @GeneratedValue
    private Long id;
    
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    @JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
    @JsonIdentityReference(alwaysAsId=true)
    private Order order;
    
    private String name;
    
    private String value;

	/**
	 * The default constructor
	 */
	public OrderAttribute() {
	    
	}
	
	/**
	 * 
	 * @param order
	 * @param name
	 * @param value
	 */
	public OrderAttribute(Order order, String name, String value) {
	   this.order = order;
	   this.name = name;
	   this.value = value;
	}
	
	/**
	 * 
	 * @param value
	 * @return
	 */
	public OrderAttribute editValue(String value) {
	    this.value = value;
	    return this;
	}
	
	/**
	 * 
	 * @return
	 */
	@Transient
	public BigDecimal getPriceValue() {
	    return new BigDecimal(this.value).divide(new BigDecimal(100));
	}
	
	/**
	 * @return the id
	 */
	public Long getId() {
		return id;
	}

    /**
     * @return the order
     */
    public Order getOrder() {
        return order;
    }

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @return the value
     */
    public String getValue() {
        return value;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @param order the order to set
     */
    public void setOrder(Order order) {
        this.order = order;
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @param value the value to set
     */
    public void setValue(String value) {
        this.value = value;
    }

}
